//
//  HomeView.m
//  NuwaRobot
//
//  Created by Kendama on 2017/12/6.
//  Copyright © 2017年 Kendama. All rights reserved.
//

#import "HomeView.h"
#import "MusicPlayView.h"

@implementation HomeView

#pragma mark --- 懒加载
- (UICollectionView *)collectionView{
    if (!_collectionView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.itemSize = CGSizeMake(px1080Width(1000)/3 - 8 , px1920Height(601)/2 - 4);
        layout.minimumLineSpacing = 0;
        layout.minimumInteritemSpacing = 0;
        layout.sectionInset = UIEdgeInsetsMake(6, 6, 6, 6);
        _collectionView = ({
            UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
            collectionView.scrollEnabled = NO;
            collectionView.backgroundColor = rgba(27,44,81,1);
            [self addSubview:collectionView];
            collectionView;
        });
        
        
        
    }return _collectionView;
}

- (UIButton *)videoCallButton
{
    if(!_videoCallButton)
    {
        UIView *superView = self;
        _videoCallButton = [[UIButton alloc]init];
        [superView addSubview:_videoCallButton];
        [_videoCallButton setBackgroundImage:imageWithName(@"but_video") forState:UIControlStateNormal];
    }
    return _videoCallButton;
}
- (UIImageView *)videoImageView
{
    if(!_videoImageView)
    {
        UIView *superView = self;
        _videoImageView = [[UIImageView alloc]init];
        [superView addSubview:_videoImageView];
        _videoImageView.image = [UIImage imageNamed:@"monitoring_bg"];
    }
    return _videoImageView;
}

- (UIButton *)fullscreenButton
{
    if(!_fullscreenButton)
    {
        UIView *superView = self.videoView;
        _fullscreenButton = [[UIButton alloc]init];
        [superView addSubview:_fullscreenButton];
        [_fullscreenButton setImage:imageWithName(@"fullscreen") forState:UIControlStateNormal];
    }
    return _fullscreenButton;
}
- (UILabel *)tipsLabel
{
    if(!_tipsLabel)
    {
        UIView *superView = self.videoView;
        _tipsLabel = [[UILabel alloc]init];
        [superView addSubview:_tipsLabel];
        [_tipsLabel setFont:fontCommonSize];
        [_tipsLabel setTextColor:[UIColor whiteColor]];
        _tipsLabel.text = @"监控连接中...";
    }
    return _tipsLabel;
}
- (UILabel *)dateLabel
{
    if(!_dateLabel)
    {
        UIView *superView = self.videoView;
        _dateLabel = [[UILabel alloc]init];
        [superView addSubview:_dateLabel];
        [_dateLabel setFont:fontWithSize(13)];
        [_dateLabel setTextColor:[UIColor whiteColor]];
//        _dateLabel.text = @"2017-11-20 12:20";
    }
    return _dateLabel;
}
- (UIActivityIndicatorView *)activityIndicatorView
{
    if(!_activityIndicatorView)
    {
        UIView *superView = self.videoView;
        _activityIndicatorView = [[UIActivityIndicatorView alloc]init];
        [superView addSubview:_activityIndicatorView];
    }
    return _activityIndicatorView;
}

- (EMCallRemoteView *)videoView
{
    if(!_videoView)
    {
        UIView *superView = self;
        _videoView = [[EMCallRemoteView alloc]init];
        _videoView.scaleMode = EMCallViewScaleModeAspectFill;
        [superView addSubview:_videoView];
    }
    return _videoView;
}

- (MusicPlayView *)musicPlayView
{
    if(!_musicPlayView)
    {
        UIView *superView = self;
        _musicPlayView = [[MusicPlayView alloc]init];
        [superView addSubview:_musicPlayView];
        _musicPlayView.backgroundColor = rgba(88,111,161,1);
    }
    return _musicPlayView;
}



- (void)masLayoutSubview
{
    __weak UIView *superView = self;
    
    [self.musicPlayView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(superView.mas_top);
        make.left.right.mas_equalTo(superView);
        make.height.mas_equalTo(px1920Height(120));
    }];
    
    [self.videoCallButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_musicPlayView.mas_bottom).with.offset(px1920Height(20));
        make.right.mas_equalTo(superView.mas_right).with.offset(-px1080Width(40));
        make.height.mas_equalTo(px1920Height(700));
        make.width.mas_equalTo(px1080Width(313));
    }];
    
    
    [self.videoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.videoCallButton.mas_top);
        make.left.mas_equalTo(superView.mas_left).with.offset(px1080Width(40));
        make.right.mas_equalTo(self.videoCallButton.mas_left).with.offset(-px1080Width(40));
        //        make.bottom.mas_equalTo(self.videoCallButton.mas_bottom);
        make.height.mas_equalTo(self.videoCallButton);
    }];
    
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.videoCallButton.mas_bottom).with.offset(px1920Height(40));
        make.centerX.mas_equalTo(superView.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(px1080Width(1000), px1920Height(601)));
    }];
    
    [self.videoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.videoImageView);
    }];
    
    [self.activityIndicatorView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(_videoView);
        make.height.width.mas_equalTo(px1920Height(80));
    }];
    
    [self.tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_activityIndicatorView.mas_bottom).with.offset(px1920Height(20));
        make.centerX.mas_equalTo(_activityIndicatorView.mas_centerX);
    }];
    
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_videoView).with.offset(px1920Height(20));
        make.left.mas_equalTo(_videoView).with.offset(px1080Width(20));

    }];
    
    [self.fullscreenButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_videoView.mas_right).with.offset(-px1080Width(20));
        make.bottom.mas_equalTo(_videoView.mas_bottom).with.offset(-px1920Height(20));
    }];
    
    self.videoView.hidden = YES;
    
//    [self.activityIndicatorView startAnimating];
}

@end
